//
//  XOWMUserOption.m
//  XOWMSDK
//
//  Created by skyline on 2018/3/9.
//  Copyright © 2018年 skyline. All rights reserved.
//
#import "XOWMUserOption.h"
CGFloat const USEROPTIONHEIGHT = 50;
@interface XOWMUserOption()
@property (nonatomic, strong) XOWMImageView *iconIMG;
@property (nonatomic, strong) XOWMImageView *img;
@property (nonatomic, strong) XOWMLabel *label;
@end
@implementation XOWMUserOption
- (instancetype)initWithTitle:(NSString *)title icon:(NSString *)icon
{
    self = [super init];
    if (self)
    {
        self.backgroundColor = [UIColor whiteColor];
        self.iconIMG.imageName = icon;
        self.titileColor = [UIColor blackColor];
        self.label.text = title;
        self.img.hidden = NO;
    }
    return self;
}

- (XOWMImageView *)iconIMG
{
    if (!_iconIMG)
    {
        _iconIMG = [[XOWMImageView alloc] init];
        _iconIMG.bounds = CGRectMake(0, 0, USEROPTIONHEIGHT - 2 * GAP, USEROPTIONHEIGHT - 2 * GAP);
        _iconIMG.layer.cornerRadius = _iconIMG.bounds.size.width / 2.0;
        _iconIMG.layer.masksToBounds = YES;
        [self addSubview:_iconIMG];
        _iconIMG.c_centerY.equal(self);
        _iconIMG.c_left.equal(self).with.coffset(GAP);
        _iconIMG.c_size.equal(self.iconIMG.bounds.size);
    }
    return _iconIMG;
}

- (XOWMImageView *)img
{
    if (!_img)
    {
        _img = [[XOWMImageView alloc] initWithImageName:@"right"];
        _img.bounds = CGRectMake(0, 0, USEROPTIONHEIGHT - 2 * GAP, USEROPTIONHEIGHT - 2 * GAP);
        [self addSubview:_img];
        _img.c_centerY.equal(self);
        _img.c_right.equal(self).with.coffset(-GAP / 2);
        _img.c_size.equal(_img.bounds.size);
    }
    return _img;
}

- (XOWMLabel *)label
{
    if (!_label)
    {
        _label = [[XOWMLabel alloc] init];
        _label.font = [UIFont systemFontOfSize:15];
        _label.textColor = self.titileColor;
        [self addSubview:_label];
        _label.c_centerY.equal(self);
        _label.c_left.equal(self.iconIMG.c_right).with.coffset(GAP);
    }
    return _label;
}

- (void)setTitileColor:(UIColor *)titileColor
{
    if (_titileColor != titileColor)
    {
        _titileColor = titileColor;
        _label.textColor = _titileColor;
    }
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    [super touchesBegan:touches withEvent:event];
    self.backgroundColor = LINE_COLOR;
    self.label.textColor = TEXT_GRAY_COLOR;
}

- (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    [super touchesEnded:touches withEvent:event];
    self.backgroundColor = [UIColor whiteColor];
    self.label.textColor = self.titileColor;
}

- (void)sendActionsForControlEvents:(UIControlEvents)controlEvents
{
    [super sendActionsForControlEvents:controlEvents];
    [self sendActionsForControlEvents:UIControlEventTouchUpInside];
}

- (void)sp_checkNetWorking {
    NSLog(@"Check your Network");
}
@end
